package treepro;

import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ivan
 */
public final class TreeTableModel extends DefaultTableModel {
    private DefaultListModel rowListModel;

    TreeTableModel(Object[][] data, Object[] columnNames) {
        super(data, columnNames);
        //this.rowListModel = lm;
    }

    public DefaultListModel getRowListModel() {
        return rowListModel;
    }

    public void setRowListModel(DefaultListModel rowListModel) {
        this.rowListModel = rowListModel;
        for (int i = 0; i < getColumnCount(); i++) {
            addColumn(getColumnName(i));
        }
    }
    
    
    
    @Override
    public void addColumn(Object columnName) {
        //super.addColumn(columnName);
        rowListModel.addElement(columnName);
    }
    
    @Override
   public void removeRow(int index) {
        //super.removeRow(index);
        rowListModel.remove(index);
    }
    
    @Override
    public boolean isCellEditable(int rowIndex, int mColIndex) {
        TreeProApp.main.treePanel.selected = (TreeProApp.main.treePanel.findByNumber(rowIndex+1, mColIndex+1));
        if (TreeProApp.main.treePanel.selected!=null)
            TreeProApp.main.treePanel.setProperties();
        else 
        if (rowIndex!=mColIndex) {
            NodeObject no1 = TreeProApp.main.treePanel.findByNumber(rowIndex+1);
            NodeObject no2 = TreeProApp.main.treePanel.findByNumber(mColIndex+1);
            if ((no1!=null)&&(no2!=null))
                TreeProApp.main.treePanel.createLine(no1, no2);
                        
        }
        return false;
    }
}
